home *** CD-ROM | disk | FTP | other *** search
- {$G+,X+,F+}
-
- {Conditional defines that may affect this unit}
- {$I AWDEFINE.INC}
-
- {*********************************************************}
- {* TCOMMAIN.PAS 1.01 *}
- {* Copyright (c) TurboPower Software 1995 *}
- {* All rights reserved. *}
- {*********************************************************}
-
- unit TcomMain;
- {-Main form for TCOM demonstration}
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, Menus, Buttons, ExtCtrls, OoMisc, AdMisc, AdTerm, AdPort,
- AdDial, AdGetNum, AdPBEdit, AdIniDB, AdPBook, AdModem, AdModDB, AdProtcl,
- AdPStat, StdCtrls, TComIni, ComParm, FlowParm, DialParm, DirParm, TComMod,
- QModem, AdStatLt, BatchUL, GenProt, ZMOpt, BPOpt, AscOpt, Kermopt, ProtSel,
- DownDir, TCSelCom, DevSel, AdExcept, AdxBP;
-
- type
- TMainForm = class(TForm)
- MainMenu: TMainMenu;
- FilesMenu: TMenuItem;
- UploadItem: TMenuItem;
- DownloadItem: TMenuItem;
- CaptureItem: TMenuItem;
- N1: TMenuItem;
- ExitItem: TMenuItem;
- PreferencesMenu: TMenuItem;
- ModemMenu: TMenuItem;
- PhonebookItem: TMenuItem;
- DialItem: TMenuItem;
- HangupItem: TMenuItem;
- TerminalFontItem: TMenuItem;
- ParametersItem: TMenuItem;
- FlowControlItem: TMenuItem;
- DeviceItem: TMenuItem;
- DialerItem: TMenuItem;
- DirectoriesItem: TMenuItem;
- ModemItem: TMenuItem;
- ModemConfigItem: TMenuItem;
- ProtocolsMenu: TMenuItem;
- GeneralItem: TMenuItem;
- ZmodemItem: TMenuItem;
- KermitItem: TMenuItem;
- ASCIIItem: TMenuItem;
- BPlusItem: TMenuItem;
- Toolbar: TPanel;
- DialBtn: TSpeedButton;
- HangupBtn: TSpeedButton;
- UploadBtn: TSpeedButton;
- DownloadBtn: TSpeedButton;
- CaptureBtn: TSpeedButton;
- ParametersBtn: TSpeedButton;
- PhonebookBtn: TSpeedButton;
- FontBtn: TSpeedButton;
- StatusLine: THeader;
- ComPort: TApdComPort;
- Emulator: TApdEmulator;
- ModemDatabase: TApdModemDBase;
- Modem: TApdModem;
- Phonebook: TApdPhonebook;
- PhonebookEditor: TApdPhonebookEditor;
- PhoneNumberSelector: TApdPhoneNumberSelector;
- Protocol: TApdProtocol;
- ProtocolLog: TApdProtocolLog;
- ProtocolStatus: TApdProtocolStatus;
- UploadSelDialog: TOpenDialog;
- SaveDialog: TSaveDialog;
- FontDialog: TFontDialog;
- LightPanel: TPanel;
- StatusLights: TApdSLController;
- CTSLight: TApdStatusLight;
- DSRLight: TApdStatusLight;
- DCDLight: TApdStatusLight;
- RILight: TApdStatusLight;
- TXDLight: TApdStatusLight;
- RXDLight: TApdStatusLight;
- ErrLight: TApdStatusLight;
- BrkLight: TApdStatusLight;
- Label1: TLabel;
- Label2: TLabel;
- Label3: TLabel;
- Label4: TLabel;
- Label5: TLabel;
- Label6: TLabel;
- Label7: TLabel;
- Label8: TLabel;
- HiddenStuffItem: TMenuItem;
- ScrollbackItem: TMenuItem;
- MainTerminal: TApdBPTerminal;
- DialerDialog: TApdDialerDialog;
- procedure FormCreate(Sender: TObject);
- procedure UploadItemClick(Sender: TObject);
- procedure DownloadItemClick(Sender: TObject);
- procedure CaptureItemClick(Sender: TObject);
- procedure ExitItemClick(Sender: TObject);
- procedure TerminalFontItemClick(Sender: TObject);
- procedure ParametersItemClick(Sender: TObject);
- procedure FlowControlItemClick(Sender: TObject);
- procedure DeviceItemClick(Sender: TObject);
- procedure DialerItemClick(Sender: TObject);
- procedure DirectoriesItemClick(Sender: TObject);
- procedure ModemItemClick(Sender: TObject);
- procedure ModemConfigItemClick(Sender: TObject);
- procedure GeneralItemClick(Sender: TObject);
- procedure ZmodemItemClick(Sender: TObject);
- procedure KermitItemClick(Sender: TObject);
- procedure ASCIIItemClick(Sender: TObject);
- procedure BPlusItemClick(Sender: TObject);
- procedure PhonebookItemClick(Sender: TObject);
- procedure DialItemClick(Sender: TObject);
- procedure HangupItemClick(Sender: TObject);
- procedure DialBtnClick(Sender: TObject);
- procedure HangupBtnClick(Sender: TObject);
- procedure UploadBtnClick(Sender: TObject);
- procedure DownloadBtnClick(Sender: TObject);
- procedure CaptureBtnClick(Sender: TObject);
- procedure ParametersBtnClick(Sender: TObject);
- procedure PhonebookBtnClick(Sender: TObject);
- procedure FontBtnClick(Sender: TObject);
- procedure ModemOk(Sender: TObject);
- procedure ModemError(Sender: TObject);
- procedure ProtocolFinish(CP: TObject; ErrorCode: Integer);
- procedure MainTerminalKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
- procedure ScrollbackToggleItemClick(Sender: TObject);
- procedure ZmodemTrigger(CP: TObject; TriggerHandle: Word);
- procedure TerminalStatus(CP: TObject; Row, Col: Byte; BufRow, BufCol: Word);
- procedure BPlusStart(Sender: TObject);
- procedure BPlusResume(CP: TObject; var Resume: TWriteFailAction);
- procedure ProtocolNextFile(CP: TObject; var FName: OpenString);
- (*{!!.01 - added}
- procedure EmulationItemClick(Sender: TObject);
- {!!.01 - added}
- procedure EmulationBtnClick(Sender: TObject);*)
- procedure SpeedButton1Click(Sender: TObject);
-
- private
- Initializing : Boolean; {TRUE if we're initializing the modem}
- UploadIdx : Integer; {number of file to upload next}
- UploadList : TStringList; {list of files to upload}
- AutoTrig : Word; {Trigger for zmodem auto start}
-
- SavedParity : TParity;
- SavedDataBits : Word;
- SavedStopBits : Word;
-
- procedure OpenComPort;
- {-Open the communications port}
- procedure SetDialerOptions;
- {-Set the dialer component properties based on configuration data}
- procedure SizeToFont;
- {-Size the terminal to the current font size}
- procedure EnableZmodemAutoStart;
- {-Add zmodem auto start trigger}
- procedure DoUpload(Prot : TProtocolType);
- {-Upload file(s)}
- procedure DoDownload(Prot : TProtocolType);
- {-Download file(s)}
- procedure ChangeLineSettingsForProtocol;
- {-Save the current line settings before protocol}
- procedure RestoreLineSettings;
- {-Restore line settings to originals}
- end;
-
- var
- MainForm: TMainForm;
-
- const
- BatchProtocols = [ptYmodem, ptYmodemG, ptZmodem, ptKermit];
- AutoStartSt = 'rz'#13;
-
- implementation
-
- function YesNo(const Question : String) : Boolean;
- {-Ask the user a yes/no question and return the answer}
- begin
- Result := (MessageDlg(Question, mtConfirmation, [mbYes, mbNo], 0) = mrYes);
- end;
-
- {$R *.DFM}
-
- procedure TMainForm.FormCreate(Sender: TObject);
-
- begin
- {not initializing the modem}
- Initializing := False;
-
- {set the font the terminal will use}
- FontData := FontDialog.Font;
-
- {no zmodem auto start trigger}
- AutoTrig := 0;
-
- {read configuration data from the INI file}
- ReadConfiguration;
-
- {read information about the modem from TCOM.INI and put that into use}
- ModemDatabase.FileName := DBFile;
- ModemDatabase.Open := True;
- ModemDatabase.ReadFromIni(ModemInfo, tsModem, IniName);
- Modem.ModemInfo := ModemInfo;
-
- {open the port}
- OpenComPort;
-
- MainTerminal.Font := FontData;
- MainTerminal.DisplayRows := 24;
- MainTerminal.DisplayRows := 25;
- MainTerminal.DisplayColumns := 79;
- MainTerminal.DisplayColumns := 80;
-
- (*Emulator.EmulatorType := Emulation; {!!.01}*)
-
- {size the terminal window to the font the user has chosen}
- SizeToFont;
-
- {open the TCOM phonebook}
- Phonebook.FileName := PhoneFile;
- Phonebook.Open := True;
-
- {put dialer options from INI file into effect}
- SetDialerOptions;
-
- {clear status line}
- StatusLine.Sections[3] := '';
-
- {if there are no modems in the database, don't let the user quick config}
- if (ModemDatabase.NumModems = 0) then
- ModemConfigItem.Enabled := False;
-
- {initilize upload stuff}
- UploadList := TStringList.Create;
- UploadIdx := 0;
-
- {change protocol log behavior} {!!.01}
- if SavePartials then {!!.01}
- ProtocolLog.DeleteFailed := dfNever {!!.01}
- else {!!.01}
- ProtocolLog.DeleteFailed := dfAlways; {!!.01}
-
- {initialize the modem}
- if ComPort.DCD then begin {!!.01}
- if (MessageDlg('Carrier detected. Send modem initialization?', {!!.01}
- mtConfirmation, [mbYes, mbNo], 0) = mrYes) then begin {!!.01}
- Initializing := True; {!!.01}
- Modem.Initialize; {!!.01}
- end; {!!.01}
- end else begin {!!.01}
- Initializing := True;
- Modem.Initialize;
- end; {!!.01}
- end;
-
- procedure TMainForm.UploadItemClick(Sender: TObject);
- var
- Frm : TProtocolSelectForm;
- Prot : TProtocolType;
-
- begin
- {exit if in scrollback mode}
- if MainTerminal.Scrollback then
- Exit;
-
- {ask the user to select a protocol}
- Prot := ptNoProtocol;
- Frm := TProtocolSelectForm.Create(Self);
- if (Frm.ShowModal = mrOK) and (Frm.ProtocolList.ItemIndex <> -1) then
- Prot := TProtocolType(Frm.ProtocolList.ItemIndex + 1);
- Frm.Free;
-
- {upload file(s) using the selected protocol}
- if (Prot <> ptNoProtocol) then
- DoUpload(Prot);
- end;
-
- procedure TMainForm.DownloadItemClick(Sender: TObject);
- var
- Frm : TProtocolSelectForm;
- DownDirFrm : TDownloadDirectoryForm;
- Prot : TProtocolType;
-
- begin
- {exit if in scrollback mode}
- if MainTerminal.Scrollback then
- Exit;
-
- {ask the user to select a protocol}
- Prot := ptNoProtocol;
- Frm := TProtocolSelectForm.Create(Self);
- if (Frm.ShowModal = mrOK) and (Frm.ProtocolList.ItemIndex <> -1) then
- Prot := TProtocolType(Frm.ProtocolList.ItemIndex + 1);
- Frm.Free;
-
- {download file(s) using the selected protocol}
- if (Prot <> ptNoProtocol) then begin
- if Prot in BatchProtocols then begin
- DownDirFrm := TDownloadDirectoryForm.Create(Self);
- if (DownDirFrm.ShowModal <> mrOK) then begin
- DownDirFrm.Free;
- Exit;
- end;
-
- Protocol.DestinationDirectory := DownDirFrm.DownloadDirEdit.Text;
- DownDirFrm.Free;
- end else begin
- SaveDialog.Title := 'Choose Download File Name';
- SaveDialog.FileName := '*.*';
- if SaveDialog.Execute then
- Protocol.FileName := SaveDialog.FileName
- else
- Exit;
- end;
-
- DoDownload(Prot);
- end;
- end;
-
- procedure TMainForm.CaptureItemClick(Sender: TObject);
- var
- CMode : TCaptureMode;
-
- begin
- {exit if in scrollback mode}
- if MainTerminal.Scrollback then
- Exit;
-
- if (MainTerminal.Capture = cmOn) then begin
- {turn off capturing}
- MainTerminal.Capture := cmOff;
- CaptureItem.Checked := False;
- end else begin
- {select a capture file name}
- SaveDialog.Title := 'Capture File Name';
- SaveDialog.FileName := '*.*';
- if SaveDialog.Execute then begin
- CMode := cmOn;
-
- {if the file exists, see if the user wants to append to the old file}
- if FileExists(SaveDialog.FileName) then
- case MessageDlg('Capture file exists. Append?', mtConfirmation, mbYesNoCancel, 0) of
- mrYes : CMode := cmAppend;
- mrCancel: Exit;
- end;
-
- {turn on capturing}
- MainTerminal.CaptureFile := SaveDialog.FileName;
- MainTerminal.Capture := CMode;
- CaptureItem.Checked := True;
- end;
- end;
- end;
-
- procedure TMainForm.ExitItemClick(Sender: TObject);
- begin
- Close;
- end;
-
- procedure TMainForm.TerminalFontItemClick(Sender: TObject);
- begin
- if FontDialog.Execute then begin
- MainTerminal.Font := FontDialog.Font;
- MainTerminal.DisplayRows := 25;
- MainTerminal.DisplayColumns := 80;
- WriteTerminalOptions;
- SizeToFont;
- end;
- end;
-
- procedure TMainForm.ParametersItemClick(Sender: TObject);
- var
- Frm : TComParametersForm;
-
- begin
- Frm := TComParametersForm.Create(Self);
- if (Frm.ShowModal = mrOK) then begin
- WritePortOptions;
- OpenComPort;
- end;
- Frm.Free;
- end;
-
- procedure TMainForm.FlowControlItemClick(Sender: TObject);
- var
- Frm : TFlowControlForm;
-
- begin
- Frm := TFlowControlForm.Create(Self);
- if (Frm.ShowModal = mrOK) then begin
- WriteFlowOptions;
- OpenComPort;
- end;
- Frm.Free;
- end;
-
- procedure TMainForm.DeviceItemClick(Sender: TObject);
- var
- Frm : TDeviceSelectForm;
-
- begin
- Frm := TDeviceSelectForm.Create(Self);
- if (Frm.ShowModal = mrOK) then begin
- WriteDeviceOptions;
- OpenComPort;
- end;
- Frm.Free;
- end;
-
- (*{!!.01 - Added}
- procedure TMainForm.EmulationItemClick(Sender: TObject);
- var
- Frm : TEmulatorForm;
-
- begin
- Frm := TEmulatorForm.Create(Self);
- if (Frm.ShowModal = mrOK) then begin
- WriteTerminalOptions;
- Emulator.EmulatorType := Emulation;
- end;
- Frm.Free;
- end;*)
-
- procedure TMainForm.DialerItemClick(Sender: TObject);
- var
- Frm : TDialerParametersForm;
-
- begin
- Frm := TDialerParametersForm.Create(Self);
- if (Frm.ShowModal = mrOK) then begin
- WriteDialerOptions;
- SetDialerOptions;
- end;
- Frm.Free;
- end;
-
- procedure TMainForm.DirectoriesItemClick(Sender: TObject);
- var
- Frm : TDirectorySettingsForm;
-
- begin
- Frm := TDirectorySettingsForm.Create(Self);
- if (Frm.ShowModal = mrOK) then begin
- WriteDataFileOptions;
-
- if not IsDirectory(DownloadDir) then
- if YesNo('Download directory does not exist. Create it?') then
- try
- MkDir(DownloadDir);
- except
- MessageDlg('Error creating directory!', mtError, [mbOK], 0);
- end;
-
- if not IsDirectory(UploadDir) then
- if YesNo('Upload directory does not exist. Create it?') then
- try
- MkDir(UploadDir);
- except
- MessageDlg('Error creating directory!', mtError, [mbOK], 0);
- end;
- end;
- Frm.Free;
- end;
-
- procedure TMainForm.ModemItemClick(Sender: TObject);
- var
- Frm : TModemForm;
-
- begin
- Frm := TModemForm.Create(Self);
- if (Frm.ShowModal = mrOK) then begin
- ModemDatabase.WriteToIni(ModemInfo, tsModem, IniName);
- Modem.ModemInfo := ModemInfo;
- end;
- Frm.Free;
- end;
-
- procedure TMainForm.ModemConfigItemClick(Sender: TObject);
- var
- Frm : TQuickModemForm;
-
- begin
- Frm := TQuickModemForm.Create(Self, ModemDatabase);
- if (Frm.ShowModal = mrOK) then begin
- ModemDatabase.WriteToIni(ModemInfo, tsModem, IniName);
- Modem.ModemInfo := ModemInfo;
-
- {send configuration string to the modem}
- if (ModemInfo.ConfigCmd <> '') then
- if YesNo('Do you want to send configuration strings to the modem?') then
- Modem.Configure;
- end;
- Frm.Free;
- end;
-
- procedure TMainForm.GeneralItemClick(Sender: TObject);
- var
- Frm : TGeneralProtocolOptionsForm;
-
- begin
- Frm := TGeneralProtocolOptionsForm.Create(Self);
- if (Frm.ShowModal = mrOK) then
- WriteProtocolOptions;
- Frm.Free;
- end;
-
- procedure TMainForm.ZmodemItemClick(Sender: TObject);
- var
- Frm : TZmodemOptionsForm;
- AutoOn : Boolean;
-
- begin
- AutoOn := ZmodemAutoSt;
-
- Frm := TZmodemOptionsForm.Create(Self);
- if (Frm.ShowModal = mrOK) then begin
- WriteZmodemOptions;
-
- {if no change in zmodem options, exit}
- if (AutoOn = ZmodemAutoSt) then
- Exit;
-
- {did the user turn on auto start?}
- if AutoOn and not ZmodemAutoSt then begin
- {disable auto start trigger}
- ComPort.RemoveTrigger(AutoTrig);
- AutoTrig := 0;
- end else
- EnableZmodemAutoStart;
- end;
- Frm.Free;
- end;
-
- procedure TMainForm.KermitItemClick(Sender: TObject);
- var
- Frm : TKermitOptionsForm;
-
- begin
- Frm := TKermitOptionsForm.Create(Self);
- if (Frm.ShowModal = mrOK) then
- WriteKermitOptions;
- Frm.Free;
- end;
-
- procedure TMainForm.ASCIIItemClick(Sender: TObject);
- var
- Frm : TAsciiOptionsForm;
-
- begin
- Frm := TAsciiOptionsForm.Create(Self);
- if (Frm.ShowModal = mrOK) then
- WriteAsciiOptions;
- Frm.Free;
- end;
-
- procedure TMainForm.BPlusItemClick(Sender: TObject);
- var
- Frm : TBPlusOptionsForm;
- BPOn : Boolean;
-
- begin
- BPOn := BPlusEnabled;
-
- Frm := TBPlusOptionsForm.Create(Self);
- if (Frm.ShowModal = mrOK) then begin
- WriteBPlusOptions;
-
- {if not change in B+ options, exit}
- if (BPOn = BPlusEnabled) then
- Exit;
-
- {did the user turn B+ on?}
- if (BPOn and not BplusEnabled) then
- MainTerminal.BPlusTriggers := True
- else
- MainTerminal.BPlusTriggers := False;
- end;
-
- Frm.Free;
- end;
-
- procedure TMainForm.PhonebookItemClick(Sender: TObject);
- begin
- PhonebookEditor.Execute;
- end;
-
- procedure TMainForm.DialItemClick(Sender: TObject);
- begin
- if PhoneNumberSelector.Execute then begin
- DialerDialog.PhoneNumber := PhoneNumberSelector.SelectedNumber;
- DialerDialog.Execute;
- end;
- end;
-
- procedure TMainForm.HangupItemClick(Sender: TObject);
- begin
- Modem.Hangup;
- end;
-
- procedure TMainForm.DialBtnClick(Sender: TObject);
- begin
- DialItemClick(Sender);
- end;
-
- procedure TMainForm.HangupBtnClick(Sender: TObject);
- begin
- HangupItemClick(Sender);
- end;
-
- procedure TMainForm.UploadBtnClick(Sender: TObject);
- begin
- UploadItemClick(Sender);
- end;
-
- procedure TMainForm.DownloadBtnClick(Sender: TObject);
- begin
- DownloadItemClick(Sender);
- end;
-
- procedure TMainForm.CaptureBtnClick(Sender: TObject);
- begin
- CaptureitemClick(Sender);
- end;
-
- procedure TMainForm.ParametersBtnClick(Sender: TObject);
- begin
- ParametersItemClick(Sender);
- end;
-
- procedure TMainForm.PhonebookBtnClick(Sender: TObject);
- begin
- PhonebookEditor.Execute;
- end;
-
- procedure TMainForm.FontBtnClick(Sender: TObject);
- begin
- TerminalFontItemClick(Sender);
- end;
-
- (*{!!.01 - Added}
- procedure TMainForm.EmulationBtnClick(Sender: TObject);
- begin
- EmulationItemClick(Sender);
- end;*)
-
- procedure TMainForm.ModemOk(Sender: TObject);
- begin
- if Initializing then begin
- StatusLine.Sections[3] := 'Modem initialized successfully!';
- Initializing := False;
- end;
- end;
-
- procedure TMainForm.ModemError(Sender: TObject);
- begin
- if Initializing then begin
- StatusLine.Sections[3] := 'Modem error!';
- Initializing := False;
- end;
- end;
-
- procedure TMainForm.ProtocolFinish(CP: TObject; ErrorCode: Integer);
- begin
- RestoreLineSettings;
-
- {turn zmodem autostart back on}
- EnableZmodemAutoStart;
-
- {turn B+ back on}
- if BPlusEnabled then
- MainTerminal.BPlusTriggers := True;
-
- MainTerminal.Active := True;
- MainTerminal.SetFocus;
- end;
-
- procedure TMainForm.MainTerminalKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
- begin
- if not MainTerminal.Scrollback and (StatusLine.Sections[3] <> '') then
- StatusLine.Sections[3] := '';
-
- if not MainTerminal.Scrollback then
- case Key of
- VK_Left : ComPort.PutString(#27'[D');
- VK_Right: ComPort.PutString(#27'[C');
- VK_Up : ComPort.PutString(#27'[A');
- VK_Down : ComPort.PutString(#27'[B');
- end;
- end;
-
- procedure TMainForm.ScrollbackToggleItemClick(Sender: TObject);
- begin
- MainTerminal.Scrollback := not MainTerminal.Scrollback;
- if MainTerminal.Scrollback then
- StatusLine.Sections[3] := 'In scrollback mode...press INS to exit'
- else begin
- StatusLine.Sections[3] := '';
- MainTerminal.SetFocus;
- end;
- end;
-
- procedure TMainForm.ZmodemTrigger(CP: TObject; TriggerHandle: Word);
- begin
- if (AutoTrig <> 0) and (TriggerHandle = AutoTrig) then begin
- if IsDirectory(DownloadDir) then
- Protocol.DestinationDirectory := DownloadDir
- else
- Protocol.DestinationDirectory := '';
- DoDownload(ptZmodem);
- end;
- end;
-
- function LeftPadCh(S : string; const Ch : Char; const Len : Byte) : String;
- {-Return a string left-padded to length len with ch}
- var
- SLen : Byte absolute S;
-
- begin
- if (Length(S) >= Len) then
- Result := S
- else if (SLen < 255) then begin
- Result[0] := Chr(Len);
- MoveFast(S[1], Result[Succ(Word(Len))-SLen], SLen);
- FillChar(Result[1], Len-SLen, Ch);
- end;
- end;
-
- procedure TMainForm.TerminalStatus(CP: TObject; Row, Col: Byte; BufRow, BufCol: Word);
- begin
- StatusLine.Sections[1] := LeftPadCh(IntToStr(BufRow), '0', 3) + ' ' +
- LeftPadCh(IntToStr(BufCol), '0', 2);
- StatusLine.Sections[2] := LeftPadCh(IntToStr(Row), '0', 2) +
- LeftPadCh(IntToStr(Col), '0', 2);
- end;
-
- procedure TMainForm.BPlusStart(Sender: TObject);
- begin
- MainTerminal.Active := False;
- ChangeLineSettingsForProtocol;
- end;
-
- procedure TMainForm.BPlusResume(CP: TObject; var Resume: TWriteFailAction);
- var
- Frm : TBPlusResume;
-
- begin
- Frm := TBPlusResume.Create(Self);
- Frm.ShowModal;
- Resume := Frm.WriteFailAction;
- Frm.Free;
- end;
-
- {!!.01 - Added}
- procedure TMainForm.ProtocolNextFile(CP: TObject; var FName: OpenString);
- begin
- if (UploadIdx <> UploadList.Count) then begin
- FName := UploadList.Strings[UploadIdx];
- Inc(UploadIdx);
- end else
- FName := '';
- end;
-
- procedure TMainForm.OpenComPort;
- {-Open the communications port}
- var
- ComFrm : TComSelectForm;
-
- function ParityChar : Char;
- begin
- case Parity of
- pNone : Result := 'N';
- pOdd : Result := 'O';
- pEven : Result := 'E';
- pMark : Result := 'M';
- pSpace: Result := 'S';
- end;
- end;
-
- begin
- {stop port and modem}
- if ComPort.Open then begin
- MainTerminal.BPlusTriggers := False;
- MainTerminal.Active := False;
- Modem.Started := False;
- StatusLights.Monitoring := False;
- ComPort.Open := False;
- if (AutoTrig <> 0) then
- ComPort.RemoveTrigger(AutoTrig);
- end;
-
- {set port options}
- ComPort.ComNumber := Ord(Com[4]) - Ord('1') + 1;
- ComPort.Baud := Baud;
- ComPort.Parity := Parity;
- ComPort.Databits := DataBits;
- ComPort.Stopbits := Stopbits;
-
- {set flow control options}
- ComPort.HWFlowOptions := HdwFlow;
- ComPort.SWFlowOptions := SfwFlow;
- ComPort.XonChar := XonChar;
- ComPort.XoffChar := XoffChar;
-
- {set device option}
- ComPort.DeviceLayer := Device;
-
- {$IFDEF Tracing}
- ComPort.TraceName := TraceFile;
- ComPort.TraceSize := 20000;
- ComPort.Tracing := tlOn;
- {$ENDIF}
-
- {$IFDEF DispatchLogging}
- ComPort.LogName := DispLogFile;
- ComPort.LogSize := 20000;
- ComPort.Logging := tlOn;
- {$ENDIF}
-
- while True do
- try
- ComPort.Open := True;
- Break;
- except
- on EOpenComm do begin
- ComFrm := TComSelectForm.Create(Self);
- if (ComFrm.ShowModal = mrOK) then begin
- Com := ComFrm.SelectedCom;
- ComPort.ComNumber := Ord(Com[4]) - Ord('1') + 1;
- WritePortOptions;
- end else
- Halt;
- ComFrm.Free;
- end else
- raise;
- end;
-
- Modem.Started := True;
- MainTerminal.Active := True;
-
- {enable zmodem auto start, if user desires}
- EnableZmodemAutoStart;
-
- {enable B+, if user desires}
- if BplusEnabled then
- MainTerminal.BPlusTriggers := True;
-
- {show status}
- StatusLine.Sections[0] := COM + ' ' + IntToStr(Baud) + ' ' +
- IntToStr(Databits) + ParityChar + IntToStr(Stopbits);
- StatusLights.Monitoring := True;
- end;
-
- procedure TMainForm.SetDialerOptions;
- {-Set the dialer component properties based on configuration data}
- begin
- DialerDialog.MaxDialTries := MaxDialTries;
- DialerDialog.RetrySecs := RetryTime;
- DialerDialog.DialerOptions := DialerOpts;
- end;
-
- procedure TMainForm.SizeToFont;
- {-Size the terminal to the current font size}
- var
- R : TRect;
- TermW : Word;
- TermH : Word;
- X : Integer;
- Y : Integer;
-
- begin
- {size the terminal window}
- GetWindowRect(MainTerminal.Handle, R);
- TermW := R.Right - R.Left;
- TermH := R.Bottom - R.Top;
- GetWindowRect(Handle, R);
- ClientWidth := TermW;
- ClientHeight := Toolbar.Height + StatusLine.Height + LightPanel.Height + TermH;
-
- {re-center the window on the screen}
- X := (Screen.Width - Width) div 2;
- Y := (Screen.Height - Height) div 2;
- if (X < 0) then X := 0;
- if (Y < 0) then Y := 0;
- SetBounds(X, Y, Width, Height);
- end;
-
- procedure TMainForm.EnableZmodemAutoStart;
- {-Add zmodem auto start trigger}
- begin
- if ZmodemAutoSt then
- AutoTrig := ComPort.AddDataTrigger(AutoStartSt, False);
- end;
-
- procedure TMainForm.DoUpload(Prot : TProtocolType);
- {-Upload file(s)}
- var
- BatchULFrm : TBatchUploadForm;
-
- begin
- {if this is a batch protocol, select the files to upload}
- if Prot in BatchProtocols then begin
- UploadList.Clear;
- BatchULFrm := TBatchUploadForm.Create(Self, UploadList);
- if (BatchULFrm.ShowModal = mrOK) and (UploadList.Count <> 0) then
- UploadIdx := 0
- else
- Exit;
-
- {otherwise, select a single file}
- end else begin
- UploadSelDialog.FileName := '*.*';
- if not UploadSelDialog.Execute then
- Exit;
-
- end;
-
- with Protocol do begin
- ProtocolType := Prot;
-
- case Prot of
- ptKermit:
- begin
- Protocol.KermitCtlPrefix := CtlPrefix;
- KermitHighbitPrefix := HibitPrefix;
- KermitMaxLen := MaxPacketLen;
- KermitRepeatPrefix := RepeatPrefix;
- KermitTerminator := Terminator;
- case ErrCheck of
- '1': BlockCheckMethod := bcmChecksum;
- '2': BlockCheckMethod := bcmChecksum2;
- '3': BlockCheckMethod := bcmCrcK;
- end;
- KermitPadCharacter := PadChar;
- KermitPadCount := PadCount;
- end;
-
- ptAscii:
- begin
- AsciiCharDelay := DelayChar;
- AsciiLineDelay := DelayLine;
- AsciiEOLChar := EolChar;
- AsciiCRTranslation := UploadCR;
- AsciiLFTranslation := UploadLF;
- AsciiSuppressCtrlZ := StopCtrlZ;
- AsciiEOFTimeout := AscTimeout;
- end;
- end;
- end;
-
- if not (Prot in BatchProtocols) then
- Protocol.FileName := UploadSelDialog.FileName;
-
- {get rid of zmodem auto start trigger}
- if ZmodemAutoSt then begin
- ComPort.RemoveTrigger(AutoTrig);
- AutoTrig := 0;
- end;
-
- {get rid of B+ triggers}
- MainTerminal.BPlusTriggers := False;
-
- MainTerminal.Active := False;
- ChangeLineSettingsForProtocol;
- Protocol.StartTransmit;
- end;
-
- procedure TMainForm.DoDownload(Prot : TProtocolType);
- {-Download file(s)}
- begin
- with Protocol do begin
- ProtocolType := Prot;
- WriteFailAction := WriteOpt;
- RTSLowForWrite := not RTSWrite;
-
- case Prot of
- ptKermit:
- begin
- Protocol.KermitCtlPrefix := CtlPrefix;
- KermitHighbitPrefix := HibitPrefix;
- KermitMaxLen := MaxPacketLen;
- KermitRepeatPrefix := RepeatPrefix;
- KermitTerminator := Terminator;
- case ErrCheck of
- '1': BlockCheckMethod := bcmChecksum;
- '2': BlockCheckMethod := bcmChecksum2;
- '3': BlockCheckMethod := bcmCrcK;
- end;
- KermitPadCharacter := PadChar;
- KermitPadCount := PadCount;
- end;
-
- ptAscii:
- begin
- AsciiCharDelay := DelayChar;
- AsciiLineDelay := DelayLine;
- AsciiEOLChar := EolChar;
- AsciiCRTranslation := DownloadCR;
- AsciiLFTranslation := DownloadLF;
- AsciiSuppressCtrlZ := StopCtrlZ;
- AsciiEOFTimeout := AscTimeout;
- end;
- end;
- end;
-
- {get rid of zmodem auto start trigger}
- if ZmodemAutoSt then begin
- ComPort.RemoveTrigger(AutoTrig);
- AutoTrig := 0;
- end;
-
- {get rid of B+ triggers}
- MainTerminal.BPlusTriggers := False;
-
- MainTerminal.Active := False;
- ChangeLineSettingsForProtocol;
- Protocol.StartReceive;
- end;
-
- procedure TMainForm.ChangeLineSettingsForProtocol;
- {-Save the current line settings before protocol}
- begin
- SavedParity := ComPort.Parity;
- SavedDataBits := ComPort.DataBits;
- SavedStopBits := ComPort.StopBits;
-
- ComPort.Parity := pNone;
- ComPort.DataBits := 8;
- ComPort.StopBits := 1;
- end;
-
- procedure TMainForm.RestoreLineSettings;
- {-Restore line settings to originals}
- begin
- ComPort.Parity := SavedParity;
- ComPort.DataBits := SavedDataBits;
- ComPort.StopBits := SavedStopBits;
- end;
-
-
- procedure TMainForm.SpeedButton1Click(Sender: TObject);
- begin
- ComPort.Tracing := tlDump;
- end;
-
- end.
-